/**
 * 最小行数
 * @type {number}
 */
var minRow = 10;

/**
 * 页面列表
 * @type {Array}
 */
var pages = [
    {"name":"在建项目","path":"app/building/index.html"},
    {"name":"运维项目","path":"app/ops/index.html"},
    {"name":"项目目标值导入","path":"importProjectTarget.html"},
    {"name":"预算数据导入","path":"importBudget.html"},
    {"name":"费用报销自动对账","path":"app/charge/chargeBill.html"}
];

$(function () {
    var html = "";
    minRow = pages.length > minRow ? pages.length : minRow;
    var rootPath = getRootPath();
    for(var i = 0;i < minRow;i++){
        if(i < pages.length){
            html += '<tr>';
            html += '<td>' + pages[i].name + '</td>';
            html += '<td><button type="button" class="layui-btn layui-btn-normal layui-btn-sm" data-href="' + pages[i].path + '" onclick="href(this)">访问</button></td>';
            html += '<td>' + rootPath + '/' + pages[i].path + '</td>';
            html += '</tr>';
        } else {
            html += '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
        }
    }
    $("#pageBody").html(html);

    console.log( getRootPath());
});

function href(dom){
    window.location.href = getRootPath() + "/" + $(dom).data("href");
}

function getRootPath() {
    //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
    var curWwwPath = window.document.location.href;
    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    //获取主机地址，如： http://localhost:8083
    var localhostPaht = curWwwPath.substring(0, pos);
    //获取带"/"的项目名，如：/uimcardprj
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    return (localhostPaht + projectName);
}